package com.amazon.model.fulfillmentInbound;

import java.io.IOException;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

/**
 * 
 * @author guoxin
 *
 */
@JsonAdapter(LabelType.Adapter.class)
public enum LabelType {

	BARCODE_2D("BARCODE_2D"),//仅在将二维条形码应用于所有包裹的货件中提供此选项。亚马逊强烈建议您使用UNIQUE选项而不是BARCODE_2D选项来获取包装标签
	PACKAGE("PACKAGE"),//箱子外包装标签
	UNIQUE("UNIQUE"),//用于为入库装运打印唯一的装运标签和承运人标签的文档数据
	PALLET("PALLET");//小于入车/满载（LTL / FTL）入库货件的打印托盘标签的文档数据
	
	private final String value;

	private LabelType(String value) {
		this.value = value;
	}

	public String value() {
		return this.value;
	}
	
	public String getValue() {
		return value;
	}
	
	public static LabelType fromValue(String text) {
		for (LabelType b : LabelType.values()) {
			if (String.valueOf(b.value).equals(text)) {
				return b;
			}
		}
		return null;
	}
	
	public static class Adapter extends TypeAdapter<LabelType> {
		@Override
		public void write(final JsonWriter jsonWriter, final LabelType enumeration) throws IOException {
			jsonWriter.value(enumeration.getValue());
		}

		@Override
		public LabelType read(final JsonReader jsonReader) throws IOException {
			String value = jsonReader.nextString();
			return LabelType.fromValue(String.valueOf(value));
		}
	}
}
